package io.unicorn.modules.water.controller;

import java.util.Arrays;
import java.util.Map;

import io.unicorn.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.unicorn.modules.water.entity.TAreaInfoEntity;
import io.unicorn.modules.water.service.TAreaInfoService;
import io.unicorn.common.utils.PageUtils;
import io.unicorn.common.utils.R;



/**
 * ${comments}
 *
 * @author LNCG
 * @email LNCG@USTL.EDU.CN
 * @date 2021-05-03 08:18:00
 */
@RestController
@RequestMapping("water/tareainfo")
public class TAreaInfoController {
    @Autowired
    private TAreaInfoService tAreaInfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("water:tareainfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tAreaInfoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{areaId}")
    @RequiresPermissions("water:tareainfo:info")
    public R info(@PathVariable("areaId") String areaId){
        TAreaInfoEntity tAreaInfo = tAreaInfoService.getById(areaId);

        return R.ok().put("tAreaInfo", tAreaInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("water:tareainfo:save")
    public R save(@RequestBody TAreaInfoEntity tAreaInfo){
        tAreaInfoService.save(tAreaInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("water:tareainfo:update")
    public R update(@RequestBody TAreaInfoEntity tAreaInfo){
        ValidatorUtils.validateEntity(tAreaInfo);
        tAreaInfoService.updateById(tAreaInfo);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("water:tareainfo:delete")
    public R delete(@RequestBody String[] areaIds){
        tAreaInfoService.removeByIds(Arrays.asList(areaIds));

        return R.ok();
    }

}
